package g4p.tests;

import java.awt.event.KeyEvent;

import processing.core.PApplet;

public class EventTest_02 extends PApplet {

	
	String[] pme = new String[] {"BACKSPACE", "TAB", "ENTER", "RETURN", "ESC", "DELETE" };
	String[] jme = new String[] {"MOUSE_CLICKED", "MOUSE_PRESSED", "MOUSE_RELEASED", "MOUSE_MOVED", "MOUSE_ENTERED", "MOUSE_EXITED", "MOUSE_DRAGGED" };

	int last_jme, last_pme;
	
	public void setup(){
		size(200,200);
		cursor(CROSS);
		registerMethod("keyEvent", this);
	}

	public void keyEvent(processing.event.KeyEvent e) {
		int me = e.getAction();
		if(me != last_pme){
			System.out.print("P_ME >> keycode: " + e.getKeyCode() + "   key: " + e.getKey() + "   action: " + e.getAction() + " " );
			System.out.println("    shift: " + e.isShiftDown() + "    control: " + e.isControlDown());
			last_pme = me;
		}
	}


	public void keyEvent(java.awt.event.KeyEvent e){
		int me = e.getID();
		boolean shiftDown = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK);
		boolean ctrlDown = ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) == KeyEvent.CTRL_DOWN_MASK);
		if(me != last_jme){
			System.out.print("J_ME >> keycode: " + e.getKeyCode() + "   key: " + e.getKeyChar() + "   action: " + e.getID());
			System.out.println("    shift: " + shiftDown + "    control: " + ctrlDown);
			last_jme = me;
		}
	}
	
	
	public void draw(){
		background(240);
	}

	public String getJavaKeyEventString(int action){
		return java.awt.event.KeyEvent.getKeyText(action);
	}	
	
	public String getKeyAction(int action){
		return "" + action;
//		if(action >= 1 && action <= 7)
//			return pme[action - 1];
//		if(action >= 500 && action <= 506)
//			return jme[action - 500];
//		return ("Mouse action error with " + action);
	}
}
